package xyz.xiaomuyu.moment_read_app.Adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;


import xyz.xiaomuyu.moment_read_app.Fragment.HomePageFragment_yinyue;
import xyz.xiaomuyu.moment_read_app.Fragment.HomePageFragment_yuedu;
import xyz.xiaomuyu.moment_read_app.Fragment.HomePageFragment_tuwen;

public class HomePagerAdapter extends FragmentStateAdapter {

    private List<String> mData = new ArrayList<>();

    public HomePagerAdapter(@NonNull FragmentActivity fragmentActivity, List<String> data) {
        super(fragmentActivity);
        mData = data;
    }


    @NonNull
    @Override
    public Fragment createFragment(int position) {
        if (mData.get(position).equals("阅读")) {
            return HomePageFragment_yuedu.newInstance(mData.get(position));
        }else if(mData.get(position).equals("音乐")){
            return HomePageFragment_yinyue.newInstance(mData.get(position));
        }else {
            return HomePageFragment_tuwen.newInstance(mData.get(position));
        }

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

}
